import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path:'/',
      redirect:'/home'
    },
    {
      path: '/home',
      name: 'home',
      component: HomeView,
      children:[
        {
           path:'/home/souye',
           name:'shouye',
           component: () => import('../views/shouye.vue')
        },
        {
           path:'/home/zhishi',
           name:'zhishi',
           component: () => import('../views/zhishi.vue')
        },
        {
          path:'/screen/employment',
          component: () => import('../views/screen/employment.vue')
        },
        {
          path:'/screen/smart',
          component: () => import('../views/screen/smart.vue')
        },
        {
          path:'/screen/security',
          component: () => import('../views/screen/security.vue')
        },
        {
          path:'/screen/equipment',
          component: () => import('../views/screen/equipment.vue')
        },
         
          
      ]
    },
    {
      path: '/login',
      name: 'login',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/Login.vue')
    }
  ] 
 
});

// 路由守卫
router.beforeEach((to,form)=>{
  if(to.path!='/login'){
    let token=localStorage.getItem('token');
    if(!token){
      return {
        path:'/login'
      }
    }
  }
})

export default router
